<?php

namespace App\Http\Requests;

use App\Models\Agent;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class AgentUpdateRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * 验证规则
     */
    public function rules()
    {
        $id = $this->request->get('id');
        return [
            'name' => ['required', Rule::unique('agents')->ignore($id), 'max:40'],
            'realname' => ['required', 'max:20'],
            'mob' => ['required', Rule::unique('agents')->ignore($id)],
            'province' => ['required'],
            'city' => ['required'],
            'country' => ['required'],
            'address' => ['required'],
            'password' => ['nullable','min:6', 'max:16'],
        ];
    }

    /**
     * 自定义错误信息
     */
    public function messages()
    {
        return [
            'name.required' => '客户名称不能留空',
            'name.max' => '客户名称不能超过40个字符',
            'name.unique' => '提交的客户名称已经存在',
            'realname.required' => '客户姓名不能留空',
            'realname.max' => '客户姓名不能超过20个字符',
            'mob.required' => '手机号不能留空',
            'mob.unique' => '提交的手机号已经存在',
            'province.required' => '省份不能留空',
            'city.required' => '地级市不能留空',
            'country.required' => '区县不能留空',
            'address.required' => '详细地址不能留空',
            'password.min' => '客户登录密码最小6位',
            'password.max' => '客户登录密码最大16位',
        ];
    }
}
